export default {
  host:'',
  user:{
    uid:'1',
  },
  url: '//www.baidu.com',
  getCookie :function (c_name) {
    if (document.cookie.length>0) {
      var c_start=document.cookie.indexOf(c_name + "=")
      if (c_start!=-1)
      {
        c_start=c_start + c_name.length+1
        var c_end=document.cookie.indexOf(";",c_start)
        if (c_end==-1) c_end=document.cookie.length
        return unescape(document.cookie.substring(c_start,c_end))
      }
    }
    return ""
  },
  IsPC : function () {
    var userAgentInfo = navigator.userAgent;
    var Agents = ["Android", "iPhone",
      "SymbianOS", "Windows Phone",
      "iPad", "iPod"];
    var flag = true;
    for (var v = 0; v < Agents.length; v++) {
      if (userAgentInfo.indexOf(Agents[v]) > 0) {
        flag = false;
        break;
      }
    }
    return flag;
  },
  iswx : function(){
    var ua = window.navigator.userAgent.toLowerCase();
    if(ua.match(/MicroMessenger/i) == 'micromessenger'){
      return true;
    }else{
      return false;
    }
  },
  wxShare : function(Option) {
    if(!this.iswx()) return;
    var _this = this;
    var time = setInterval(function () {
      try {
        if (!wx || !oe_wxconfig) return;
      } catch (e) {
        return;
      }
      clearTimeout(time);
      //初始化
      if(!Option) Option={};
      var config = oe_wxconfig,
        title = Option.title ? Option.title : "悼念黄大年",
        summary = Option.cont ? Option.cont : "最单纯的赤胆忠心的海归科学家",
        link = Option.url ? Option.url : _this.url,
        thumb = "http://h5.oeeee.com/h5/v17/hdn/logo.jpg",
        content = {
          title: title,
          desc: summary,
          link: link,
          imgUrl: thumb,
          type: '',
          dataUrl: '',
          success: function () {
          },
          cancel: function () {
          }
        }

      wx.config({
        debug: false,
        appId: config.appId,
        timestamp: config.timestamp,
        nonceStr: config.nonceStr,
        signature: config.signature,
        jsApiList: [
          'onMenuShareAppMessage', 'onMenuShareTimeline', 'onMenuShareQQ', 'onMenuShareWeibo'
        ]
      });
      wx.checkJsApi({
        jsApiList: ['onMenuShareAppMessage', 'onMenuShareTimeline', 'onMenuShareQQ', 'onMenuShareWeibo'],
        success: function (res) {
        }
      });
      wx.ready(function () {
        wx.onMenuShareAppMessage(content);
        wx.onMenuShareTimeline(content);
        wx.onMenuShareQQ(content);
        wx.onMenuShareWeibo(content);
      });
    },500);
  },
  init(next){
    if(!this.getCookie('wx_h5_wxuid') && location.hostname == 'h5.oeeee.com'){
      location.href = this.url;
      return;
    }else{
      next();
    }
    var _this = this;
    if(this.iswx()){
      window.onload = function () {
        var jwx1 = document.createElement('script');
        jwx1.setAttribute('src','http://res.wx.qq.com/open/js/jweixin-1.0.0.js');
        document.body.appendChild(jwx1);
        var jwx2 = document.createElement('script');
        jwx2.setAttribute('src','https://m.mp.oeeee.com/helper.php?m=WxHelper&a=config&domain=oeeee.com');
        document.body.appendChild(jwx2);
        _this.wxShare();
      }
    }
  }
}
